import 'dart:async';
import 'dart:math';

import 'package:flutter/material.dart';
import 'package:flutter_hooks/flutter_hooks.dart';
import '../../util/screen_util.dart';

class PlayerInner extends HookWidget{
  final bool playing;

  PlayerInner({super.key, this.playing=false});

  @override
  Widget build(BuildContext context) {
    final screen=Screen(context);
    final d=useState(0.0);

    Timer(Duration(milliseconds: 16), (){
      if(playing){
        d.value+=1;
      }
    });

    return Container(
      height: screen.calc(800),
      child: Stack(
        children: [
          //唱片
          Positioned(
            left: screen.calc(41),
            top: screen.calc(182),
            child: Transform.rotate(
                angle: d.value*pi/180,
                child: Container(
                  width: screen.calc(618),
                  height: screen.calc(618),
                  child: Stack(
                    children: [
                      //封面
                      Center(
                          child: Container(
                            color: Colors.black,
                            child: Image.asset('assets/tmp_cover_7.jpg', width: screen.calc(400), height: screen.calc(400)),
                          )
                      ),
                      //唱片
                      Positioned.fill(
                          child: Image.asset('assets/player-disc.png')
                      )
                    ],
                  ),
                )
            ),
          ),

          //arm
          Positioned(
            left: screen.calc(325),
            top: screen.calc(24),
            child: Transform.rotate(
              origin: Offset(screen.calc(-137), screen.calc(-80)),
              angle: playing?30*pi/180:0,
              child: Image.asset('assets/player-arm.png', width: screen.calc(314), height: screen.calc(198)),
            ),
          ),
        ],
      ),
    );
  }
}